package com.jjh.consts;




public class Result {

    private Integer code;

    private String msg;

    private Object data;


    public Result(Integer code,String msg,Object data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public Result(Object data){
        this.data = data;
    }
    public Result(ResEnum resEnum){
        this.code = resEnum.getCode();
        this.msg = resEnum.getMsg();
    }

    public Result(ResEnum resEnum,Object data){
        this.code = resEnum.getCode();
        this.msg = resEnum.getMsg();
        this.data = data;
    }


    /**
     * 没有数据的返回成功方法
     * @return
     */
    public static Result ok(){
         return new Result(ResEnum.OK);
    }

    /**
     * 有数据的返回成功方法
     * @return
     */
    public static Result ok(Object data){
        return new Result(ResEnum.OK,data);
    }

    /**
     * 自定义的返回结果
     * @param code 自定义状态码
     * @param msg 自定义消息
     * @param data 自定义结果
     * @return
     */
    public static Result ok(Integer code,String msg, Object data){
        return new Result(code,msg,data);
    }


    /**
     * 没有数据的默认错误结果
     * @return
     */
    public static Result error(){
        return new Result(ResEnum.ERROR);
    }

    /**
     * 带数据的错误结果
     * @param resEnum
     * @param data
     * @return
     */
    public static Result error(ResEnum resEnum,Object data){
        return new Result(resEnum,data);
    }

    public static Result error(Object data){
        return new Result(ResEnum.ERROR,data);
    }


    /**
     * 自定义返回错误结果
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static Result error(Integer code,String msg,Object data){
        return new Result(code,msg,data);
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
